package com.hzhc.controller.sysmanage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.dto.UserDto;
import com.hzhc.entity.SysMsgNotify;
import com.hzhc.entity.UserMember;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.*;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.SysMsgNotifyVo;
import com.hzhc.vo.TrainPlanDetailVo;
import com.hzhc.vo.TrainPlanVo;
import com.hzhc.vo.YwOrderCntrVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @author dongcy
 * @date 2024/9/3 9:09
 * @description SysMsgNotifyController   消息提醒
 */
@RestController
@RequestMapping("/sysMsgNotify")
@RequiredArgsConstructor
public class SysMsgNotifyController extends BaseController {
    private final TrainPlanDetailService detailService;
    private final YwOrderCntrService ywOrderCntrService;

    private final SysMsgNotifyService msgNotifyService;
    private final CompanyInfoService infoService;

    /**
     * 消息提醒 list
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/getList")
    public ResultUtil<List<SysMsgNotifyVo>> getList(HttpServletRequest request, @RequestBody SysMsgNotifyVo vo){
        Page<SysMsgNotifyVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<SysMsgNotifyVo> list = msgNotifyService.getList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 右上角点击 修改为已读
     * @param request
     * @param notify
     * @return
     */
    @RequestMapping("/updateReadState")
    public ResultUtil<T> updateReadState(HttpServletRequest request,@RequestBody SysMsgNotify notify){
        return msgNotifyService.updateReadState(notify);
    }

    /**
     * 查寻计划消息明细
     */
    @RequestMapping("/getTrainPlanDetailList")
    @ResponseBody
    public ResultUtil<List<TrainPlanDetailVo>> getTrainPlanDetailList(HttpServletRequest request, @RequestBody TrainPlanDetailVo vo){
        UserDto member = TokenUtil.getUserMember(request);
        vo.setConsignee(infoService.getById(member.getCompanyId()).getName());
        Page<TrainPlanDetailVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<TrainPlanDetailVo> list = new ArrayList<>();
        if (vo.getTsNum().toString().startsWith("2024")){
            //到达箱推送通知
            list = detailService.getDdCntrDetail(page,vo);
        }else{
            //卸车完工通知
            list = detailService.getTrainPlanDetail(page,vo);
        }



        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 导出完工提醒清单(暂时不用)
     */
    @RequestMapping( "/exportReport")
    @SysTemLog(operModul = "导出完工提醒清单-导出", operType = "导出", operDesc = "导出完工提醒清单", modular = "PC")
    public void exportMonthReport(TrainPlanDetailVo vo, HttpServletRequest request, HttpServletResponse response) {
        msgNotifyService.exportReport(vo,request,response);
    }

}
